package com.ml.springboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ml.springboot.mapper.EmployeeMapper;
import com.ml.springboot.pojo.Employee;
import com.ml.springboot.pojo.query.EmployeeQuery;
import com.ml.springboot.service.IEmployeeService;
import com.ml.springboot.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public PageResult list(EmployeeQuery employeeQuery) {
        PageHelper.startPage(employeeQuery.getPage(), employeeQuery.getLimit());
        //当前分页数据
        List<Employee> list = employeeMapper.list(employeeQuery);
        PageInfo<Employee> pageInfo = new PageInfo<>(list);
        int totalCount = (int) pageInfo.getTotal();
        return new PageResult(0,"",totalCount,list);
    }

    @Override
    public void deletedById(Integer id) {
        employeeMapper.deleteById(id);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        for (Integer id : ids) {
            employeeMapper.deleteById(id);
        }
    }

    @Override
    public void add(Employee employee) {
        employee.setId(140);
        employeeMapper.add(employee);
    }

    @Override
    public Employee selectById(Integer id) {
        return employeeMapper.selectById(id);
    }

    @Override
    public void update(Employee employee) {
        employeeMapper.update(employee);
    }

    @Override
    public Employee login(String name, String password) {
        return employeeMapper.login(name,password);
    }

    @Override
    public void updateStatus(Integer id, Integer status) {
        employeeMapper.updateStatus(id,status);
    }

    @Override
    public List<Employee> selectAll(Long id) {
        return employeeMapper.selectAll();
    }

    @Override
    public List<Employee> selectsuoyou() {
        return employeeMapper.selectsuoyou();

    }

}
